package com.fsl.springbootstreamkafka.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dell
 */
@RestController
public class KafkaController {

    private final KafkaTemplate kafkaTemplate;

    private final String topic;

    @Autowired
    public KafkaController(KafkaTemplate kafkaTemplate,
                           @Value("${kafka.topic}") String topic) {
        this.kafkaTemplate = kafkaTemplate;
        this.topic = topic;
    }

    @PostMapping("/message/send")
    public String sendMessage(@RequestParam String message){
        kafkaTemplate.send(topic,message);
        return "success";
    }
}
